package com.boot.security.server.controller;

import java.util.List;

import com.boot.security.server.model.AppReportexam;
import com.boot.security.server.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.dao.AppReportlabDao;
import com.boot.security.server.model.AppReportlab;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/appReportlabs")
public class AppReportlabController {

    @Autowired
    private AppReportlabDao appReportlabDao;

    @PostMapping
    @ApiOperation(value = "保存")
    public AppReportlab save(@RequestBody AppReportlab appReportlab) {
        appReportlabDao.save(appReportlab);

        return appReportlab;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public AppReportlab get(@PathVariable Long id) {
        return appReportlabDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public AppReportlab update(@RequestBody AppReportlab appReportlab) {
        appReportlabDao.update(appReportlab);

        return appReportlab;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return appReportlabDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<AppReportlab> list(PageTableRequest request) {
                return appReportlabDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        appReportlabDao.delete(id);
    }

    /**
     * 查询绑定关系
     * @param appReportlab
     * @return R
     */
    @PostMapping("/find")
    @ResponseBody
    public R findinfo(@RequestBody AppReportlab appReportlab){

        //  Map<String,Object> map = new HashMap<String,Object  >();
//        String timestarm=params.get("timestarm").toString();
//        //    map=entityToMap(appAccount);
//        AppAccount appAccount =new AppAccount();
        return new R<>(appReportlabDao.getBylist(appReportlab.getCardno()) );

        //    return new R<>(  bxbFbqksDao.getById(bxbFbqks.getId()));
    }
}
